#-*- codeing = utf-8 -*-
#@Time : 2020/9/13 14:23
#@Author : 阳某
#@File : 无头浏览器和规避检测.py
#@Software : PyCharm

from selenium import webdriver
from time import sleep
# 实现无可视化界面（无头浏览器）     phantomjs
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
# 实现检测规避
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_experimental_option("excludeSwitches",['enable-automation'])
# 如何实现让selenium规避被检测的风险
driver = webdriver.Chrome(chrome_options = chrome_options,options = option)
driver.get('https://www.baidu.com')
print(driver.page_source)
sleep(2)
driver.quit()